#!/bin/bash

if [ "x$DOCKER_HOST" == "x" ]; then
  # On Linux, assume DOCKER_HOST is the unix socket. On other platforms, if an
  # arbitrary `docker` CLI command can be run, then we can also assume that the
  # daemon is listening on the unix socket (or else the docker CLI would not
  # work)
  if [ "$(uname -s)" == "Linux" ] || docker info >/dev/null 2>&1; then
    DOCKER_HOST=unix:///var/run/docker.sock
    echo export DOCKER_HOST=$DOCKER_HOST
  else
    echo "DOCKER_HOST needs to be set"
    exit 1
  fi
fi


if [[ "$DOCKER_HOST" == unix:///* ]]; then
  DOCKER_HOST_RAW=localhost
  DOCKER_HOST_ADDRESS=127.0.0.1
else
  DOCKER_HOST_RAW=$(echo $DOCKER_HOST | sed 's/^[a-zA-Z]\{1,\}:\/\///')
  DOCKER_HOST_ADDRESS=$(echo $DOCKER_HOST_RAW | cut -d: -f1)
fi
HELIOS_URI=http://$DOCKER_HOST_ADDRESS:5801

echo export DOCKER_HOST_RAW=$DOCKER_HOST_RAW
echo export DOCKER_HOST_ADDRESS=$DOCKER_HOST_ADDRESS
echo export HELIOS_URI=$HELIOS_URI
